﻿using Marmat.Forms;
using Marmat.Foundation;
using Marmat.Template.WinForm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace 测试项目.TestDemo
{
    class TestFirstDemoViewFormController : Marmat.Template.WinForm.DocumentViewFormController<TestDemoEntity>, IExport, IViewFormBatchAction, ISearchControlController
    {
        public void ButtonClick(IButtonItem item, object[] records)
        {
            MessageBox.Show(string.Join(",", records));
        }

        public bool FieldBuilder(string fieldName)
        {
            return true;
        }

        public IEnumerable<IButtonItem> GetBatchActionCollection()
        {
            yield return new ButtonItem("批量打印");
            yield return new ButtonItem("批量审批");
        }


        public override void InitializationSearchControl(ISearchControl searchControl)
        {
            base.InitializationSearchControl(searchControl);
            searchControl.Filter.Add<TestDemoEntity>(x => new { x.Name, x.Status });
            searchControl.Filter.AddField("Name", null, typeof(string), "id in(SELECT id from xxx where {0})");
            searchControl.Filter.AddGroup("今日到港柜数", null, "");
            //searchControl.Filter.GetString();
            //searchControl.Value.Add("Name", "张三", "李四");
        }

        public override void ReceiveNotification(string channel, params object[] arguments)
        {
            this.SearchControl.Value.Clear();
            this.SearchControl.Value.Add("今日到港柜数");
        }

        //public void InitializationSearchControl(ISearchControl searchControl)
        //{
        //    this.InitializationSearchControl(searchControl, x => new { x.Name, x.Status });
        //    
        //}

        object IExport.Export()
        {
            List<TestDemoEntity> items = new List<TestDemoEntity>();
            items.Add(new TestDemoEntity());
            items.Add(new TestDemoEntity());
            items.Add(new TestDemoEntity());
            return items.ToArray();
        }

        object IExport.ExportAll()
        {
            throw new NotImplementedException();
        }
    }
}
